package DataStructure;

import java.util.Collections;
import java.util.LinkedList;

/* wrap the built-in type LinkedList to class queue  
 * 
 * */
public class queue {
	public LinkedList<node> datalist;

	public queue() {
		datalist = new LinkedList<node>();
	}

	public boolean isEmpty() {
		return datalist.isEmpty();
	}

	public boolean in(node n) {
		return datalist.offer(n);
	}

	public node out() {
		return datalist.poll();
	}

	public node getHead() {
		return datalist.getFirst();
	}

	/*
	 * sort the queue with increasing sequence
	 */
	public void sort() {
		Collections.sort(datalist);
	}

	
	/*
	 * If the queue contains the given node,
	 * return the position index,
	 * or return -1.
	 */
	public int contains(node n) {
		for (int i = 0; i < datalist.size(); i++) {
			if (datalist.get(i).StateEquals(n))
				return i;
		}
		return -1;
	}
	public node get(int index){
		return datalist.get(index);
	}
	public node remove(int index){
		node n=datalist.get(index);
		datalist.remove(index);
		return n;
	}
	
	/*
	 * Print the content of the queue.
	 * Used for test the program.
	 * */
	public void print(){
		for(int i=0;i<datalist.size();i++){
			System.out.print("A:("+datalist.get(i).getS().getAx()+","+datalist.get(i).getS().getAy()+")-----");
			System.out.print("B:("+datalist.get(i).getS().getBx()+","+datalist.get(i).getS().getBy()+")-----");
			System.out.println(datalist.get(i).getCost());
		}
	}

}
